<%@ page import="com.cinsea.htmlselect.service.OptionService" %>
<%@ page import="com.cinsea.common.Env" %>
<%@ page import="java.util.List" %>
<%@ page contentType="text/html; charset=UTF-8" %>
<%@ include file="/common/common.jsp" %>
<%--
  ~ Copyright (c) 2011. 晨熹软件版权所有。
  --%>

<%
    String processid=StringUtil.null2String(request.getParameter("processid"));
    String k6=StringUtil.trimToNull(request.getParameter("k6"));
    //测试用processid="f2d1fb3e2d2d8113012d2d919edd0007";
    String kpiSql="delete from ut_kpiscore where prjid=?";
    JdbcDao jdbcDao=(JdbcDao)Env.getBean("jdbcDao");
    jdbcDao.update(kpiSql,new Object[]{processid}) ;

    String teacherSql="select b.processid as id,b.name from ut_trainningcontent a,ut_teacher b where a.teacher=b.processid and a.iskp=1 and a.processid=?";
    List teachers=jdbcDao.queryForList(teacherSql,new Object[]{processid}) ;
    List<Option> kcOptions=optionService.getOptions("8a00010f2d5e315a012d72e0caaf01eb",null);
    List<Option> jsOptions=optionService.getOptions("8a00010f2d5e315a012d72e1601901ec",null);
    List<Option> jxOptions=optionService.getOptions("8a00010f2d5e315a012d72e19a0601ed",null);
    List<Option> xyOptions=optionService.getOptions("8a00010f2d5e315a012d72e1d76c01ee",null);
    //课程
    for(Option o:kcOptions){
        String k1=StringUtil.trimToNull(request.getParameter("k1_"+o.getId()));
        String k2=StringUtil.trimToNull(request.getParameter("k2_"+o.getId()));
        String k3=StringUtil.trimToNull(request.getParameter("k3_"+o.getId()));
        String k4=StringUtil.trimToNull(request.getParameter("k4_"+o.getId()));
        String k5=StringUtil.trimToNull(request.getParameter("k5_"+o.getId()));
        kpiSql="insert into ut_kpiscore(prjid,kid,k1,k2,k3,k4,k5,k6) values(?,?,?,?,?,?,?,?)" ;
        jdbcDao.update(kpiSql,new Object[]{processid,o.getId(),k1,k2,k3,k4,k5,k6});
    }
    //讲师
    for (Object t : teachers) {
        String tid = ((Map) t).get("id").toString();
        String tname = ((Map) t).get("name").toString();
        for (Option o : jsOptions) {
            String k1 = StringUtil.trimToNull(request.getParameter("k1_" + o.getId()+"_"+tid));
            String k2 = StringUtil.trimToNull(request.getParameter("k2_" + o.getId()+"_"+tid));
            String k3 = StringUtil.trimToNull(request.getParameter("k3_" + o.getId()+"_"+tid));
            String k4 = StringUtil.trimToNull(request.getParameter("k4_" + o.getId()+"_"+tid));
            String k5 = StringUtil.trimToNull(request.getParameter("k5_" + o.getId()+"_"+tid));
            kpiSql = "insert into ut_kpiscore(prjid,teacherid,kid,k1,k2,k3,k4,k5,k6) values(?,?,?,?,?,?,?,?,?)";
            jdbcDao.update(kpiSql, new Object[]{processid, tid,o.getId(), k1, k2, k3, k4, k5, k6});
        }
    }
    //教学
    for(Option o:jxOptions){
        String k1=StringUtil.trimToNull(request.getParameter("k1_"+o.getId()));
        String k2=StringUtil.trimToNull(request.getParameter("k2_"+o.getId()));
        String k3=StringUtil.trimToNull(request.getParameter("k3_"+o.getId()));
        String k4=StringUtil.trimToNull(request.getParameter("k4_"+o.getId()));
        String k5=StringUtil.trimToNull(request.getParameter("k5_"+o.getId()));
        kpiSql="insert into ut_kpiscore(prjid,kid,k1,k2,k3,k4,k5,k6) values(?,?,?,?,?,?,?,?)" ;
        jdbcDao.update(kpiSql,new Object[]{processid,o.getId(),k1,k2,k3,k4,k5,k6});
    }
    //学员
    for(Option o:xyOptions){
        String k1=StringUtil.trimToNull(request.getParameter("k1_"+o.getId()));
        String k2=StringUtil.trimToNull(request.getParameter("k2_"+o.getId()));
        String k3=StringUtil.trimToNull(request.getParameter("k3_"+o.getId()));
        String k4=StringUtil.trimToNull(request.getParameter("k4_"+o.getId()));
        String k5=StringUtil.trimToNull(request.getParameter("k5_"+o.getId()));
        kpiSql="insert into ut_kpiscore(prjid,kid,k1,k2,k3,k4,k5,k6) values(?,?,?,?,?,?,?,?)" ;
        jdbcDao.update(kpiSql,new Object[]{processid,o.getId(),k1,k2,k3,k4,k5,k6});
    }
    response.sendRedirect("scoreview.jsp?processid="+processid);

%>
